package cn.cvs.service;

import cn.cvs.dao.SysUserDao;
import cn.cvs.pojo.TSysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl  implements UserService{
    @Resource
    SysUserDao userDao;

    @Override
    public TSysUser login(String account, String password) throws Exception {
        TSysUser params = new TSysUser(account);
        TSysUser loginUser =null;
        List<TSysUser> userList =userDao.getUserByPojo(account);
        if (null !=userList && userList.size()>0){
            loginUser =userList.get(0);
            if (null !=loginUser){
                if (password.equals(loginUser.getPassword())){
                    return loginUser;
                }else{
                    throw  new RuntimeException("密码不正确");
                }
            }
        }else{
            throw  new RuntimeException("账户不存在");
        }
        return null;
    }

    @Override
    public List<TSysUser> getUserByRoleIdPage(String realName,Long roleId, Integer pageStart, Integer pageSize) {
        pageStart =(pageStart-1)*pageSize;
        return userDao.getUserByRoleIdPage(realName,roleId,pageStart,pageSize);
    }

    @Override
    public int getUserCount(TSysUser userParam) {
        return userDao.getUserCount(userParam);
    }

    @Override
    public boolean addUser(TSysUser sysUser) {
        return userDao.addUser(sysUser)==1;//?true:false;
    }

    @Override
    public List<TSysUser> getUserListByPojo(TSysUser param) {
        return userDao.getUserListByPojo(param);
    }

    @Override
    public boolean updateUser(TSysUser sysUser) {
        return userDao.updateUser(sysUser);
    }

}
